﻿using System.Data.Entity.ModelConfiguration;
using CH.FourBoards.LagerWalti.Persistence.Entities;

namespace CH.FourBoards.LagerWalti.Persistence.Mapping
{
    internal class ProductMap : EntityTypeConfiguration<Product>
    {
        internal ProductMap()
        {
            #region Primary Key and Row Version

            HasKey(t => t.Id);

            // RowVersion for optimistic locking
            //Property(t => t.Version).IsRowVersion();

            #endregion

            #region Foreign Keys

            Property(t => t.CategoryId).IsRequired();

            #endregion

            #region Properties

            Property(t => t.Name).IsRequired().HasMaxLength(500);
            Property(t => t.BundleSize).IsRequired();

            #endregion

            #region Relationships

            HasRequired(t => t.Category).WithMany().HasForeignKey(t => t.CategoryId);

            #endregion

        }
    }
}
